﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数据绑定
{
    //实现接口INotifyPropertyChanged，就能实现数据通知
    class MainViewModel :INotifyPropertyChanged
    {
        public static int cnt=3;
        public MainViewModel()
        {
            Username = "How are you!";
            Task.Run(async () => { 
                cnt++;
                await Task.Delay(3000);
                Username =( cnt++).ToString();
            });
        }

        private string username;

        public string Username
        {
            get { return username; }
            set 
            { 
                username = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Username"));
            }
        }

        //接口实现函数
        public event PropertyChangedEventHandler PropertyChanged;

    }
}
